import { BaseWindow } from "../../../component/window/BaseWindow";
import { Language } from "../../../../extend/language/Language";
import { NationalTreasureInfo } from "../../model/NationalTreasureInfo";
import { StringHelper } from "../../../../com/gengine/utils/StringHelper";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { Cache } from "../../cache/Cache";
import { AIManager } from "../../scene/ai/AIManager";
import { AIType } from "../../scene/ai/AIType";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../resource/ImagesConst";
import { ObjCreate } from "../common/ObjCreate";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { SecTimerView } from "../common/SecTimerView";
import { NationalTreasureCheckPanel } from "./NationalTreasureCheckPanel";
import { TaskProcessPanel } from "../task/imgtxt/TaskProcessPanel";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { TaskTargetInfo } from "../../model/TaskTargetInfo";
//class NationalTreasureWindow
    
    export  class NationalTreasureWindow extends BaseWindow
    {
        constructor()
        {
            super();
            setSize(300, 200);
            title = Language.getString(27025);
            if (NationalTreasureWindow._instance) 
            {
                throw new Error("NationalTreasureWindow is single!");
            }
            return;
        }

        public updateData(arg1: NationalTreasureInfo): void
        {
            this.joinUpdate(arg1);
            var loc1=Language.getString(27026);
            loc1 = StringHelper.substitute(loc1, HTMLUtil.addColor(arg1.activeDateStr, "#ffff00"), this.npcLinkTxt);
            this._textInfo.htmlText = HTMLUtil.addColor(loc1, GlobalStyle.color1) + "<u><a href=\'event:-1\'>" + HTMLUtil.addColor(Language.getString(27067), "#00ff00") + "</a></u>";
            this._imgBody.updateData(this._textInfo, null, false, this.onFlyFootClickHandler);
            if (arg1.checkInStart) 
            {
                if (arg1.isStartTime()) 
                {
                    this.onTimerOutHandler();
                }
                else 
                {
                    this._timeValue.visible = true;
                    this._openTxt.visible = false;
                    this._timeValue.colorChange = ["#00ff00", "#ff0000"];
                    this._timeValue.setLeftTime(arg1.dateDis);
                    this._timeValue.timeOutHandler = this.onTimerOutHandler;
                }
            }
            else 
            {
                this.notOpen();
            }
            return;
        }

        /* internal  */notOpen(): void
        {
            this._openTxt.visible = true;
            this._timeValue.visible = false;
            this._openTxt.text = Language.getString(27027);
            return;
        }

        /* internal  */onTimerOutHandler(): void
        {
            this._openTxt.visible = true;
            this._timeValue.visible = false;
            this._openTxt.text = Language.getString(27028);
            return;
        }

        /* internal  */get npcLinkTxt(): string
        {
            var loc1=null;
            if (!this._npcLinkTxt) 
            {
                loc1 = Cache.instance.scene.getNationalTaskNPC();
                this._npcLinkTxt = "<u><a href=\'event: 0\'>" + HTMLUtil.addColor(loc1.name, "#00ff00") + "</a></u>@0";
            }
            return this._npcLinkTxt;
        }

        public joinUpdate(arg1: NationalTreasureInfo): void
        {
            this._checkPanel.updateData(arg1);
            return;
        }

        protected clear(): void
        {
            this._checkPanel.dispose();
            this._timeValue.dispose();
            this._imgBody.dispose();
            return;
        }

        /* internal  */onTotoTargetHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            if (arg1.text != "-1") 
            {
                this._target = Cache.instance.scene.getNearlyNationalSignInNpc();
                AIManager.onAutoPathAIControl(this._target, AIType.AI_AutoPath);
            }
            else 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.NationalTreasureShowDetial));
            }
            return;
        }

        /* internal  */onFlyFootClickHandler(): void
        {
            this._target = Cache.instance.scene.getNearlyNationalSignInNpc();
            AIManager.onAIControl(this._target, AIType.AI_Convey);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._windowCenterB = ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB);
            addChild(this._windowCenterB);
            this._textInfo = ObjCreate.createTextField("", 0, 0, -1, -1, null, GlobalStyle.getTextFormatDefaultFont(GlobalStyle.textFormat1));
            this._textInfo.width = width - 70;
            this._textInfo.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._textInfo.selectable = false;
            this._textInfo.multiline = true;
            this._textInfo.wordWrap = true;
            this._textInfo.textColor = GlobalStyle.color1Uint;
            this._textInfo.filters = [FilterConst.nameGlowFilter];
            this._textInfo.htmlText = HTMLUtil.addColor(Language.getString(27026), GlobalStyle.color1) + "<u><a href=\'event:-1\'>" + HTMLUtil.addColor(Language.getString(27067), "#00ff00") + "</a></u>";
            this._textInfo.addEventListener(flash.events.TextEvent.LINK, this.onTotoTargetHandler);
            this._textInfo.width = 270;
            this._textInfo.height = 36;
            this._textInfo.x = 20;
            this._textInfo.y = 42;
            addChild(this._textInfo);
            this._timeTxt = new Object /* flash.text.TextField */();
            this._timeTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._timeTxt.selectable = false;
            this._timeTxt.mouseEnabled = false;
            this._timeTxt.textColor = 16763906;
            this._timeTxt.filters = [FilterConst.nameGlowFilter];
            this._timeTxt.text = Language.getString(27015);
            addChild(this._timeTxt);
            this._timeValue = new SecTimerView();
            this._timeValue.setParse("hh: mm: ss");
            addChild(this._timeValue);
            this._openTxt = new Object /* flash.text.TextField */();
            this._openTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._openTxt.selectable = false;
            this._openTxt.mouseEnabled = false;
            this._openTxt.textColor = 16776960;
            this._openTxt.text = Language.getString(27028);
            this._openTxt.filters = [FilterConst.nameGlowFilter];
            addChild(this._openTxt);
            this._checkInfoTxt = new Object /* flash.text.TextField */();
            this._checkInfoTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._checkInfoTxt.selectable = false;
            this._checkInfoTxt.mouseEnabled = false;
            this._checkInfoTxt.textColor = GlobalStyle.color2Uint;
            this._checkInfoTxt.text = Language.getString(27029);
            this._checkInfoTxt.filters = [FilterConst.nameGlowFilter];
            addChild(this._checkInfoTxt);
            this._checkPanel = new NationalTreasureCheckPanel();
            addChild(this._checkPanel);
            this._tipsTxt = new Object /* flash.text.TextField */();
            this._tipsTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._tipsTxt.selectable = false;
            this._tipsTxt.mouseEnabled = false;
            this._tipsTxt.textColor = 65280;
            this._tipsTxt.filters = [FilterConst.nameGlowFilter];
            this._tipsTxt.htmlText = HTMLUtil.addColor(Language.getString(27030), "#00ff00");
            addChild(this._tipsTxt);
            this._imgBody = new TaskProcessPanel();
            addChild(this._imgBody);
            return;
        }

        protected /* override */ updateSize(): void
        {
            super.updateSize();
            _windowCenter.setSize(this.width - 22, this.height - titleHeight + 9);
            _windowCenter.x = 11;
            _windowCenter.y = 33;
            this._windowCenterB.setSize(_windowCenter.width - 8, _windowCenter.height - 8);
            this._windowCenterB.x = _windowCenter.x + 4;
            this._windowCenterB.y = _windowCenter.y + 4;
            this._timeTxt.width = 200;
            this._timeTxt.height = 25;
            this._timeTxt.x = this._textInfo.x;
            this._timeTxt.y = this._textInfo.y + this._textInfo.textHeight + 10;
            this._timeValue.x = this._timeTxt.x + this._timeTxt.textWidth;
            this._timeValue.y = this._timeTxt.y;
            this._openTxt.x = this._timeValue.x;
            this._openTxt.y = this._timeValue.y;
            this._checkInfoTxt.width = 100;
            this._checkInfoTxt.height = 20;
            this._checkInfoTxt.x = this._textInfo.x;
            this._checkInfoTxt.y = this._timeTxt.y + this._timeTxt.textHeight + 10;
            this._checkPanel.x = this._checkInfoTxt.x + this._checkInfoTxt.textWidth + 2;
            this._checkPanel.y = this._checkInfoTxt.y;
            this._tipsTxt.width = 100;
            this._tipsTxt.height = 20;
            this._tipsTxt.x = this._checkInfoTxt.x;
            this._tipsTxt.y = height - 32;
            this._imgBody.x = 0;
            this._imgBody.y = 0;
            return;
        }

        public /* override */ hide(): void
        {
            super.hide();
            Dispatcher.dispatchEvent(new DataEvent(EventName.NationalTreasureWindowClose));
            this.clear();
            return;
        }

        public static get instance(): NationalTreasureWindow
        {
            if (!NationalTreasureWindow._instance) 
            {
                NationalTreasureWindow._instance = new NationalTreasureWindow();
            }
            return NationalTreasureWindow._instance;
        }

        protected /* var */_windowCenterB: ScaleBitmap;

        /* internal */ /* var */_textInfo: Object /* flash.text.TextField */;

        /* internal */ /* var */_timeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_timeValue: SecTimerView;

        /* internal */ /* var */_openTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_checkInfoTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_tipsTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_checkPanel: NationalTreasureCheckPanel;

        /* internal */ /* var */_imgBody: TaskProcessPanel;

        /* internal */ /* var */_target: TaskTargetInfo;

        /* internal */ /* var */_npcLinkTxt: string;

        /* internal */ static /* var */_instance: NationalTreasureWindow;
    }
